;;;; -*- mode: Scheme; -*-
;;; 
(define mix-linked-version Mix_Linked_Version)
(define mix-init Mix_Init)
(define mix-quit Mix_Quit)

(define (mix-open-audio frequency-int formatflag-u16 channels-int chunksize-int)
  ;; 之前自己手撸的  2023年3月23日22:28:27
  (if (= 0 (Mix_OpenAudio frequency-int formatflag-u16 channels-int chunksize-int))
      #t
      (assertion-violation 'mix-open-audio "can't open audio at channels" channels-int)))

(define mix-open-audio-device Mix_OpenAudioDevice)
(define mix-allocate-channels Mix_AllocateChannels)
(define mix-query-spec Mix_QuerySpec)

(define mix-load-wav-rw Mix_LoadWAV_RW)
(define mix-load-wav (lambda (str) (Mix_LoadWAV_RW (SDL_RWFromFile str "rb") 1))) ;参照了源代码,这样搞不知道会不会内存溢出,这里还是有问题,SDL_RWFrom会返回一个内存地址,但是不是Mix的有效参数

(define mix-load-mus Mix_LoadMUS)
(define mix-load-mus-rw Mix_LoadMUS_RW)
(define mix-load-mus-type-rw Mix_LoadMUSType_RW)
(define mix-quick-load-wav Mix_QuickLoad_WAV)
(define mix-quick-load-raw Mix_QuickLoad_RAW)
(define mix-free-chunk Mix_FreeChunk)
(define mix-free-music Mix_FreeMusic)
(define mix-get-num-chunk-decoders Mix_GetNumChunkDecoders)
(define mix-get-chunk-decoder Mix_GetChunkDecoder)
(define mix-has-chunk-decoder Mix_HasChunkDecoder)
(define mix-get-num-music-decoders Mix_GetNumMusicDecoders)
(define mix-get-music-decoder Mix_GetMusicDecoder)
(define mix-has-music-decoder Mix_HasMusicDecoder)
(define mix-get-music-type Mix_GetMusicType)
(define mix-set-post-mix Mix_SetPostMix)
(define mix-hook-music Mix_HookMusic)
(define mix-hook-music-finished Mix_HookMusicFinished)
(define mix-get-music-hook-data Mix_GetMusicHookData)
(define mix-channel-finished Mix_ChannelFinished)
(define mix-register-effect Mix_RegisterEffect)
(define mix-unregister-effect Mix_UnregisterEffect)
(define mix-unregister-all-effects Mix_UnregisterAllEffects)
(define mix-set-panning Mix_SetPanning)
(define mix-set-position Mix_SetPosition)
(define mix-set-distance Mix_SetDistance)
(define mix-set-reverse-stereo Mix_SetReverseStereo)
(define mix-reserve-channels Mix_ReserveChannels)
(define mix-group-channel Mix_GroupChannel)
(define mix-group-channels Mix_GroupChannels)
(define mix-group-available Mix_GroupAvailable)
(define mix-group-count Mix_GroupCount)
(define mix-group-oldest Mix_GroupOldest)
(define mix-group-newer Mix_GroupNewer)
(define mix-play-channel-timed Mix_PlayChannelTimed)
(define mix-play-music Mix_PlayMusic)
(define mix-fade-in-music Mix_FadeInMusic)
(define mix-fade-in-music-pos Mix_FadeInMusicPos)
(define mix-fade-in-channel-timed Mix_FadeInChannelTimed)
(define mix-volume Mix_Volume)
(define mix-volume-chunk Mix_VolumeChunk)
(define mix-volume-music Mix_VolumeMusic)
(define mix-halt-channel Mix_HaltChannel)
(define mix-halt-group Mix_HaltGroup)
(define mix-halt-music Mix_HaltMusic)
(define mix-expire-channel Mix_ExpireChannel)
(define mix-play-channel Mix_PlayChannel) ;chez-sdl和thunder都没提供这个接口  2023年4月9日12:03:38
(define mix-fade-out-channel Mix_FadeOutChannel)
(define mix-fade-out-group Mix_FadeOutGroup)
(define mix-fade-out-music Mix_FadeOutMusic)
(define mix-fading-music Mix_FadingMusic)
(define mix-fading-channel Mix_FadingChannel)
(define mix-pause Mix_Pause)
(define mix-resume Mix_Resume)
(define mix-paused Mix_Paused)
(define mix-pause-music Mix_PauseMusic)
(define mix-resume-music Mix_ResumeMusic)
(define mix-rewind-music Mix_RewindMusic)
(define mix-paused-music Mix_PausedMusic)
(define mix-set-music-position Mix_SetMusicPosition)
(define mix-playing Mix_Playing)
(define mix-playing-music Mix_PlayingMusic)
(define mix-set-music-cmd Mix_SetMusicCMD)
(define mix-set-synchro-value Mix_SetSynchroValue)
(define mix-get-synchro-value Mix_GetSynchroValue)
(define mix-set-sound-fonts Mix_SetSoundFonts)
(define mix-get-sound-fonts Mix_GetSoundFonts)
(define mix-each-sound-font Mix_EachSoundFont)
(define mix-get-chunk Mix_GetChunk)
(define mix-close-audio Mix_CloseAudio)

(define (sdl-mix-library-init . l)
  (load-shared-object
   (if (null? l)
       (case (machine-type)
	 ((i3nt  ti3nt  a6nt  ta6nt)  "SDL2_mixer.dll")
	 ((i3le  ti3le  a6le  ta6le)  "SDL2_mixer.so")
	 ((i3osx ti3osx a6osx ta6osx) "SDL2_mixer.dylib"))
       (car l)))
  )
